/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package DAO;

import Bean.*;
import DataBase.TransacionException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Sixviv
 */
public class DAOMaestro extends  AbstractDAO<Maestro>{

    @Override
    public void insertar(Maestro maestro) throws TransacionException {
         String sql = "insert into maestro(idPersona, clave)values(?,?);";
        try {
            this.adminConsulta.iniciar();
            List<Object> params = new ArrayList();
            params.add(maestro.getIdPersona());
            params.add(maestro.getClave());
            adminConsulta.doUpdate(sql, params);
            this.adminConsulta.finalizar();
        } catch (SQLException ex) {
            adminConsulta.rollBack();
        }
    }

    @Override
    public void borrar(String condicion) throws TransacionException {
        String sql = "delete from maestro where idMaestro= ? ";
        try{
            this.adminConsulta.iniciar();
            List<Object> params = new ArrayList();
            params.add(condicion);
            this.adminConsulta.doUpdate(sql, params);
            this.adminConsulta.finalizar();
        }catch (SQLException ex) {
            adminConsulta.rollBack();
        }
    }

    @Override
    public void actualizar(Maestro maestro, String condicion) throws TransacionException {
         String sql = "update maestro set idPersona=?, clave=? where idMaestro = ?";
        try{
            this.adminConsulta.iniciar();
            List<Object> params = new ArrayList();
            params.add(maestro.getIdPersona());
            params.add(maestro.getClave());
            params.add(condicion);
            adminConsulta.doUpdate(sql, params);
            this.adminConsulta.finalizar();
        }catch(SQLException ex){
            adminConsulta.rollBack();
        }
    }

    @Override
    public List<Maestro> buscar(String condicion, List<Object> params) {
          List<Maestro> result=null;
        String sql = "select * from maestro "+condicion;
        pstmt= adminConsulta.prepareTheStatementForQuery(sql, params);
        result = adminConsulta.ejecutarSeleccion(pstmt, Maestro.class);
        return result;
    }

    public List<Maestro> getMaestroByPersona(String condicion){
        String sql = "where idPersona = ?";
        List<Object> params = new ArrayList();
        params.add(condicion);
        return buscar(sql,params);
    }

}
